home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Linux Cubed Series 7: Sunsite
/
Linux Cubed Series 7 - Sunsite Vol 1.iso
/
system
/
admin
/
linuxcon.000
/
linuxcon
/
linuxconf-1.6
/
dnsconf
/
tbfile.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-09-08
|
902b
|
53 lines
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <limits.h>
#include "internal.h"
PUBLIC TBFILE::TBFILE(
const char *_defpath) // Default path
{
defpath = strdup(_defpath);
nbopen = 0;
cur = NULL;
}
PUBLIC TBFILE::~TBFILE()
{
while (nbopen > 0) ::fclose (tb[--nbopen]);
free (defpath);
}
/*
Open a new file and remember the one currently open.
(put in on a stack). fclose will get it back.
Return the FILE handle or NULL if can't open.
*/
PUBLIC FILE *TBFILE::fopen (const char *fname, const char *mode)
{
char abspath[PATH_MAX];
if (fname[0] != '/'){
sprintf (abspath,"%s/%s",defpath,fname);
fname = abspath;
}
FILE *ret = xconf_fopen (fname,mode);
if (ret != NULL){
tb[nbopen++] = ret;
cur = ret;
}
return ret;
}
PUBLIC void TBFILE::fclose ()
{
if (nbopen > 0){
::fclose (cur);
cur = NULL;
nbopen--;
if (nbopen > 0) cur = tb[nbopen-1];
}
}